package com.example.g5project.service.impl;

import com.example.g5project.entity.frontEndObject.NewChat;
import com.example.g5project.entity.frontEndObject.NewChatFrontEnd;
import com.example.g5project.exception.EntityNotExistException;
import com.example.g5project.repository.repo.NewChatRepo;
import com.example.g5project.service.NewChatService;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.ArrayList;

/**
 * @author Hu Zirui
 * @version 1.0.0
 * @ClassName ConsultantServiceImpl.java
 * @Description TODO
 * @createTime 2022年03月09日 13:18:00
 */
@Service
@Transactional
public class NewChatServiceImpl implements NewChatService {
    private final NewChatRepo newChatRepo;

    public NewChatServiceImpl(NewChatRepo newChatRepo) {
        this.newChatRepo = newChatRepo;
    }

    @Override
    public ArrayList<NewChat> getChatMsgByNameAndDate(String name, String date) {
        return newChatRepo.getChatMsgByNameAndDate(name, date);
    }

    @Override
    public void addNewChat(NewChat newChat) {
        newChatRepo.addNewChat(newChat);
    }

    @Override
    public ArrayList<NewChat> getAllChatMsgByConsultantName(String name) {
        return newChatRepo.getAllChatMsgByConsultantName(name);
    }

    @Override
    public void updateNewChatComment(Integer id, String content) {
        newChatRepo.updateNewChatComment(id, content);
    }

    @Override
    public String getEndTimeById(Integer id) {
        return newChatRepo.getEndTimeById(id);
    }

    @Override
    public ArrayList<NewChat> getAllMsg() {
        return newChatRepo.getAllMsg();
    }

    @Override
    public NewChat getRecentMsg() {
        return newChatRepo.getRecentMsg();
    }

    @Override
    public String getRecentMsgEndTime() {
        return newChatRepo.getRecentMsgEndTime();
    }

    @Override
    public void updateNewChatCommentByID(Integer id, NewChat newChat) throws EntityNotExistException {
        newChatRepo.updateById(id, newChat);
    }

    @Override
    public void updateHoldTimeByName(String name, String hold_time) {
        newChatRepo.updateHoldTimeByName(name, hold_time);
    }

    @Override
    public void updateHoldTimeByChatID(Integer id, String hold_time) {
        newChatRepo.updateHoldTimeByChatID(id, hold_time);
    }

    @Override
    public ArrayList<NewChatFrontEnd> getAllChatMsgByConsultantNameStr(String name) {
        ArrayList<NewChat> arrayList = newChatRepo.getAllChatMsgByConsultantName(name);
        ArrayList<NewChatFrontEnd> resultList = new ArrayList<>();
        for (NewChat newChat : arrayList) {
            resultList.add(new NewChatFrontEnd(newChat));
        }
        return resultList;
    }

    @Override
    public ArrayList<NewChatFrontEnd> getAllMsgStr() {
        ArrayList<NewChat> arrayList = newChatRepo.getAllMsg();
        ArrayList<NewChatFrontEnd> resultList = new ArrayList<>();
        for (NewChat newChat : arrayList) {
            resultList.add(new NewChatFrontEnd(newChat));
        }
        return resultList;
    }
}
